/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */

using UnityEngine;

namespace TFrameWork.Module.ActionEditor
{
    public class AudioEventItemStyle : CommonEventItemStyle
    {
        public override Color eventColor => new Color(0.98f, 0.75f, 0.03f, 0.4f);

        public override int RealLenth
        {
            get
            {
                if (AudioData == null || AudioData.audioClip == null)
                {
                    return 10;
                }

                AudioClip clip = AudioData.audioClip;
                return (int)(clip.length * ActionEditor.Instance.ActionData.FrameRote);
            }
        }

        public override TrackEventBase eventData => AudioData;

        private AudioEvent AudioData;
        

        public void Init(AudioTrackStyle.CommonChildTrackBase parent, AudioEvent data)
        {
            AudioData = data;
            InitComponent(parent);
        }

        public override void ShowContent()
        {
            base.ShowContent();
            if (AudioData.audioClip)
            {
                if (!string.IsNullOrEmpty(AudioData.trackName))
                {
                    Name.text = AudioData.trackName;
                }
                else
                {
                    Name.text = AudioData.audioClip.name;
                }
            }
            else
            {
                Name.text = "未设置画资源";
            }
        }

        public override void HitEventPreView(int frameIndex)
        {
            base.HitEventPreView(frameIndex);
            if (frameIndex == AudioData.startIndex && ActionEditor.Instance.IsPlaying)
                EditorAudioUtility.PlayAudio(AudioData.audioClip, 0);
        }

    }
}
